﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WanCommon.Entity;



namespace WanCommon.ExceptionModule
{
    public class ExceptionInfoTool
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="excption"></param>
        public static void Add(Exception excption)
        {
            string content = RgUtility .Debug.DebugLog.GetMutilLineJson(excption);
            using (var db = DbFactory.GetDb())
            {
                ExceptionInfo ex = new ExceptionInfo();
                ex.Content = content;
                ex.InsertTime = DateTime.Now;
                db.From<ExceptionInfo>().Add(ex,i=>i,i=>i.Id);
            }
        }
        public static List<ExceptionInfo> GetExcptionLs()
        {
            using (var db = DbFactory.GetDb())
            {
                return db.From<ExceptionInfo>().Select(i => i);
            }
        }
        public static ExceptionInfo GetException(int id)
        {
            using (var db = DbFactory.GetDb())
            {
                return db.From<ExceptionInfo>().Where(i => i.Id == id).Select(i => i).FirstOrDefault();
            }
        }
    }
}
